package flc.ast.adapter;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class AlbumAdapter extends StkProviderMultiAdapter<MyAlbumBean> {

    private int selPosition=0;

    public AlbumAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(100));
        addItemProvider(new AlbumProvider());
    }

    public int getSelPosition() {
        return selPosition;
    }

    public void setSelPosition(int selPosition) {
        this.selPosition = selPosition;
    }

    private class AlbumProvider extends BaseItemProvider<MyAlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyAlbumBean bean) {
            if (bean.getListData() == null || bean.getListData().size() == 0) {
                baseViewHolder.setImageResource(R.id.ivAlbumItemImg, R.drawable.wuzhaopianxiangce1);
            } else {
                Glide.with(getContext()).load(bean.getListData().get(0))
                        .into((ImageView) baseViewHolder.getView(R.id.ivAlbumItemImg));
            }
            baseViewHolder.setText(R.id.tvAlbumItemName, bean.getName());
            baseViewHolder.setText(R.id.tvAlbumItemNum, bean.getListData().size() + getContext().getString(R.string.unit_album));
//                baseViewHolder.setText(R.id.tvAlbumItemNum, bean.getListData().size() + getContext().getString(R.string.unit_zhang));
//            if (baseViewHolder.getBindingAdapterPosition()==selPosition){
//                baseViewHolder.getView(R.id.tvAlbumItemName).setVisibility(View.VISIBLE);
//                baseViewHolder.getView(R.id.tvAlbumItemNum).setVisibility(View.VISIBLE);
//                baseViewHolder.getView(R.id.llAlbumItem).setVisibility(View.INVISIBLE);
//            }else {
//                baseViewHolder.getView(R.id.tvAlbumItemName).setVisibility(View.INVISIBLE);
//                baseViewHolder.getView(R.id.tvAlbumItemNum).setVisibility(View.INVISIBLE);
//                baseViewHolder.getView(R.id.llAlbumItem).setVisibility(View.VISIBLE);
//            }
            baseViewHolder.itemView.setTag(bean);
        }
    }
}
